<% layout('/layouts/default.html', {title: '任务部署信息表(主)管理', libs: ['validate','fileupload','dataGrid']}){ %>
<style>
	.lhTime .select2-container{
		width: 60% !important;
		margin-left: 10px;
		margin-right: 10px;
	}
	#table2 tr{
		padding-bottom: 10px;
		display: block;
	}
	.addku{
		position: absolute;
		width: 30px;
		border: 1px solid #d3d4d6;
		text-align: center;
		height: 30px;
		line-height: 30px;
		border-radius: 4px;
		margin-left: 5px;
	}
	.ui-jqgrid .ui-jqgrid-htable td {height:100px;}
	.ui-jqgrid .ui-jqgrid-htable td div {padding:4px 0px 3px 2px;}
	.ui-jqgrid .ui-jqgrid-frozen .ui-jqgrid-htable td div {height:100px!important;}
	.ui-jqgrid .editable {
		height: 60px!important;
	}
</style>
<div class="main-content">
	<div class="box box-main">

		<#form:form id="inputForm" model="${taskInfoRefine}" action="${ctx}/taskdeploy/dcSupTaskInfoRefine/updateRefineTime" method="post" class="form-horizontal">
		<div class="box-body">
			<#form:hidden path="id"/>
			<#form:hidden path="taskId"/>
			<#form:hidden path="taskLeaderOrg"/>
			<#form:hidden path="taskLeaderOrgName"/>
			<#form:hidden path="isNewRecord"/>



			<div class="form-unit">${text('反馈要求分解')}</div>
			<div class="row">
				<div class="row multipleFeedback">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> </label>
							<div class="col-sm-10">
								<table id="scheBusiTaskFeedbackDataGrid"></table>
								<!--<a href="#" id="testDataChildDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> 增加固定反馈时间</a>-->
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="box-footer">
			<div class="row">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('提 交')}</button>&nbsp;
					<button type="button" class="btn btn-sm btn-default btnList" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
				</div>
			</div>
		</div>
	</#form:form>
</div>
</div>
<% } %>
<script>
	// 初始化多次反馈表DataGrid对象
	$("#scheBusiTaskFeedbackDataGrid").dataGrid({
		data:${toJson(taskInfoRefine.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}, hidden:false},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}, hidden:false},
			{header:'${text("分阶段目标任务")}', name:'feedbackRequire', width:500, editable:false, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control required', 'rows':'1'}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}, hidden:true}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		// editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime,feedbackRequire', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});

	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					// js.closeCurrentTabPage(function(contentWindow){
					// 	contentWindow.page();
					// });
				}
			}, "json");
		}
	});

	// 定义周和月份
	const weekData = [{ id: 1, text: '周一' }, { id: 2, text: '周二' }, { id: 3, text: '周三' }, { id: 4, text: '周四' }, { id: 5, text: '周五' }, { id: 6, text: '周六' }, { id: 7, text: '周日' }];
	const monthData = [{ id: 1, text: '1' }, { id: 2, text: '2' }, { id: 3, text: '3' }, { id: 4, text: '4' },
		{ id: 5, text: '5' }, { id: 6, text: '6' }, { id: 7, text: '7' }, { id: 8, text: '8' }, { id: 9, text: '9' },
		{ id: 10, text: '10' }, { id: 11, text: '11' }, { id: 12, text: '12' }, { id: 13, text: '13' }, { id: 14, text: '14' },
		{ id: 15, text: '15' }, { id: 16, text: '16' }, { id: 17, text: '17' }, { id: 18, text: '18' }, { id: 19, text: '19' },
		{ id: 20, text: '20' }, { id: 21, text: '21' }, { id: 22, text: '22' }, { id:23, text: '23' }, { id: 24, text: '24' },
		{ id: 25, text: '25' }, { id: 26, text: '26' }, { id: 27, text: '27' }, { id:28, text: '28' },{ id:29, text: '29' },{ id:30, text: '30' },{ id:31, text: '31' }];
	// 反馈要求数据
	let addData = ${toJson(taskInfoRefine.dcSupTaskInfoAddList)}
	$(function () {
		feedbackCircle()
		if (!addData || !addData.length) {
			getMutiFeedBackTimes();
		}
	})

	// 选择反馈周期
	function feedbackCircle(){
		if($("#feedbackWay").val()=='3'){
			$("#feedbackRate").select2('destroy').empty();
			$("#feedbackRate").select2({data: weekData,placeholder:'请选择',allowClear:true})
			$("#yearMonth").text('每周：');
			$("#feedbackRateShow").css("display","block");
		}else if($("#feedbackWay").val()=='2'){
			$("#feedbackRate").select2('destroy').empty();
			$("#feedbackRate").select2({data: monthData,placeholder:'请选择',allowClear:true})
			$("#yearMonth").text('每月：');
			$("#feedbackRateShow").css("display","block");
		}else if($("#feedbackWay").val()=='1'){
			$("#feedbackRate").select2('destroy').empty();
			$("#feedbackRate").select2({data: monthData,placeholder:'请选择',allowClear:true})
			$("#yearMonth").text('每季度首月：');
		}else{
			$("#feedbackRateShow").css("display","none");
		}
		$("#feedbackRate").val('${dcSupTaskInfo.feedbackRate}').trigger("change");
	}
	// 根据多次反馈，反馈频次获取后台所有反馈时间段
	function getMutiFeedBackTimes(){
		let start = '${dcSupTaskInfo.taskStartTime,"yyyy-MM-dd HH:mm"}';
		let end = '${dcSupTaskInfo.taskEndTime,"yyyy-MM-dd HH:mm"}';

		if($("#feedbackWay").val()!=null&&$("#feedbackRate").val()!=null){
			$.post("${ctx}/taskdeploy/dcSupTaskInfo/getMutiFeedBackTimes",{taskStartTime:start,taskEndTime:end,feedbackWay:$("#feedbackWay").val(),feedbackRate:$("#feedbackRate").val()},function (data){
				if(data.result == Global.TRUE){
					$('#scheBusiTaskFeedbackDataGrid').dataGrid('setParam', {
						data:data.data
					}, true).dataGrid('reloadGrid');
				}else{
					js.showMessage(data.message);
				}
			});
		};
	}
</script>